package com.yulang.security.config;

import com.yulang.security.mobile.SmsCodeSender;
import com.yulang.security.mobile.SmsSend;
import com.yulang.security.strategy.CustonInvialSessionStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.core.session.SessionRegistry;
import org.springframework.security.web.session.InvalidSessionStrategy;

@Configuration
public class SecurityBeanConfig {


    @Lazy
    @Autowired
    private SessionRegistry sessionRegistry;

    /**
     * 默认情况下采用如下实例 如果存在其他的实例这个实例就失效了
     * @return
     */
    @Bean
    @ConditionalOnMissingBean(SmsSend.class)
    public SmsSend smsSend() {
        return new SmsCodeSender();
    }


    @Bean
    @ConditionalOnMissingBean(InvalidSessionStrategy.class)
    public InvalidSessionStrategy invialSessionStrategy() {
        return new CustonInvialSessionStrategy(sessionRegistry);
    }

}
